package org.zbclan.bf2.rcon.ui;

import java.util.Map;

import org.zbclan.bf2.rcon.client.VHello;

import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.ClientWidget;

@ClientWidget(VHello.class)
public class Hello extends AbstractField {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2477676132773194973L;

	public void setText(String text) {
		setValue(text);
	}

	public String getText() {
		return (String) getValue();
	}

	@Override
	public void paintContent(PaintTarget target) throws PaintException {

		// Superclass writes any common attributes in the paint target.
		super.paintContent(target);

		// Add the currently selected color as a variable in the paint
		// target.
		target.addVariable(this, "text", getText());

		return;
	}

	@Override
	public void changeVariables(Object source, Map<String, Object> variables) {

		// Let superclass read any common variables.
		super.changeVariables(source, variables);
		// Sets the currently selected color
		if (variables.containsKey("text") && !isReadOnly()) {
			final String text = (String) variables.get("text");
			// Changing the property of the component will
			// trigger a ValueChangeEvent
			setValue(text, true);
		}

		return;
	}

	@Override
	public Class<?> getType() {
		return String.class;
	}
}
